<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netty ChannelPipeline 与 ChannelHandler 协作机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            display: inline-block;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .code-dots {
            display: flex;
            gap: 8px;
        }
        
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        
        .list-item {
            position: relative;
            padding-left: 30px;
        }
        
        .list-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 10px;
            width: 8px;
            height: 8px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
        }
        
        .flow-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            position: relative;
            overflow: hidden;
        }
        
        .flow-card::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.5; }
            50% { transform: scale(1.1); opacity: 0.3; }
        }
        
        .mermaid {
            background: white;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 600;
        }
        
        .step-number {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            font-weight: 600;
            margin-right: 12px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center relative z-10">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 leading-tight">
                Netty 核心架构解析
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">
                深入理解 ChannelPipeline 与 ChannelHandler 的协作机制
            </p>
            <div class="flex justify-center gap-6 text-sm md:text-base">
                <div class="flex items-center gap-2">
                    <i class="fas fa-network-wired"></i>
                    <span>高性能网络框架</span>
                </div>
                <div class="flex items-center gap-2">
                    <i class="fas fa-layer-group"></i>
                    <span>责任链模式</span>
                </div>
                <div class="flex items-center gap-2">
                    <i class="fas fa-bolt"></i>
                    <span>异步事件驱动</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <p class="text-lg leading-relaxed text-gray-700">
                在 Netty 中，<code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">ChannelPipeline</code> 和 
                <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">ChannelHandler</code> 
                是处理网络请求和响应的核心组件。它们的协作工作流程非常重要，以便高效地处理 I/O 操作。
            </p>
        </div>

        <!-- ChannelPipeline Section -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-stream mr-3 text-purple-600"></i>ChannelPipeline 介绍
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">ChannelPipeline</code> 
                是一个用于处理入站和出站事件的处理器链。它是 
                <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">Channel</code> 
                的一个重要组成部分，管理着所有处理 I/O 操作的 
                <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">ChannelHandler</code>。
            </p>
            
            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="bg-gradient-to-br from-blue-50 to-purple-50 p-6 rounded-xl">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-arrow-down text-2xl text-blue-600 mr-3"></i>
                        <h3 class="text-xl font-semibold text-gray-800">入站处理</h3>
                    </div>
                    <p class="text-gray-700">处理来自网络的数据（如解码数据）</p>
                </div>
                
                <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-arrow-up text-2xl text-purple-600 mr-3"></i>
                        <h3 class="text-xl font-semibold text-gray-800">出站处理</h3>
                    </div>
                    <p class="text-gray-700">处理要发送到网络的数据（如编码数据）</p>
                </div>
            </div>
        </div>

        <!-- ChannelHandler Section -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-cogs mr-3 text-purple-600"></i>ChannelHandler 介绍
            </h2>
            <p class="text-lg leading-relaxed text-gray-700 mb-6">
                <code class="bg-purple-100 text-purple-700 px-2 py-1 rounded">ChannelHandler</code> 
                是 Netty 中处理业务逻辑的主要接口。它可以处理数据的编码和解码、事件的处理、以及网络连接的管理。
            </p>
            
            <div class="grid md:grid-cols-2 gap-6 mt-8">
                <div class="bg-gradient-to-r from-indigo-500 to-purple-600 text-white p-6 rounded-xl">
                    <h3 class="text-xl font-semibold mb-3">
                        <i class="fas fa-download mr-2"></i>Inbound Handler
                    </h3>
                    <p>处理入站数据（例如，解码数据）</p>
                </div>
                
                <div class="bg-gradient-to-r from-purple-600 to-pink-600 text-white p-6 rounded-xl">
                    <h3 class="text-xl font-semibold mb-3">
                        <i class="fas fa-upload mr-2"></i>Outbound Handler
                    </h3>
                    <p>处理出站数据（例如，编码数据）</p>
                </div>
            </div>
        </div>

        <!-- Workflow Visualization -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>工作流程可视化
            </h2>
            
            <div class="mermaid">
                graph LR
                    A[客户端请求] -->|网络传输| B[Channel]
                    B --> C[ChannelPipeline]
                    C --> D[入站Handler 1<br/>解码器]
                    D --> E[入站Handler 2<br/>业务逻辑]
                    E --> F[入站Handler 3<br/>聚合器]
                    F --> G[应用程序处理]
                    G --> H[生成响应]
                    H --> I[出站Handler 1<br/>编码器]
                    I --> J[出站Handler 2<br/>加密]
                    J --> K[Channel]
                    K -->|网络传输| L[客户端响应]
                    
                    style A fill:#f093fb,stroke:#f5576c,stroke-width:2px
                    style L fill:#f093fb,stroke:#f5576c,stroke-width:2px
                    style G fill:#667eea,stroke:#764ba2,stroke-width:2px,color:#fff
                    style C fill:#ffd93d,stroke:#ff6b6b,stroke-width:2px
            </div>
        </div>

        <!-- Detailed Workflow -->
        <div class="content-card rounded-2xl p-8 mb-8">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-tasks mr-3 text-purple-600"></i>详细工作流程
            </h2>

            <!-- Request Reception -->
            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <span class="step-number">1</span>请求的接收
                </h3>
                <div class="ml-11 space-y-3">
                    <div class="list-item text-gray-700">
                        <strong>接收数据：</strong>当数据到达服务器